unit uNetApi;

interface

uses
  Windows;

const
  FILTER_TEMP_DUPLICATE_ACCOUNT     = $1;
  FILTER_NORMAL_ACCOUNT             = $2;
  FILTER_INTERDOMAIN_TRUST_ACCOUNT  = $8;
  FILTER_WORKSTATION_TRUST_ACCOUNT  = $10;
  FILTER_SERVER_TRUST_ACCOUNT       = $20;

  UF_SCRIPT                         = $1;
  UF_ACCOUNTDISABLE                 = $2;
  UF_HOMEDIR_REQUIRED               = $8;
  UF_LOCKOUT                        = $10;
  UF_PASSWD_NOTREQD                 = $20;
  UF_PASSWD_CANT_CHANGE             = $40;
  UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED= $80;
  UF_TEMP_DUPLICATE_ACCOUNT         = $100;
  UF_NORMAL_ACCOUNT                 = $200;
  UF_INTERDOMAIN_TRUST_ACCOUNT      = $800;
  UF_WORKSTATION_TRUST_ACCOUNT      = $1000;
  UF_SERVER_TRUST_ACCOUNT           = $2000;

  ERROR_SUCCESS                     = 0;
  NO_ERROR                          = 0;
  ERROR_INVALID_FUNCTION            = 1;
  ERROR_FILE_NOT_FOUND              = 2;
  ERROR_PATH_NOT_FOUND              = 3;
  ERROR_TOO_MANY_OPEN_FILES         = 4;
  ERROR_ACCESS_DENIED               = 5;
  ERROR_INVALID_HANDLE              = 6;
  ERROR_ARENA_TRASHED               = 7;
  ERROR_NOT_ENOUGH_MEMORY           = 8;
  ERROR_INVALID_BLOCK               = 9;
  ERROR_BAD_ENVIRONMENT             = 10;
  ERROR_BAD_FORMAT                  = 11;
  ERROR_INVALID_ACCESS              = 12;
  ERROR_INVALID_DATA                = 13;
  ERROR_OUTOFMEMORY                 = 14;
  ERROR_INVALID_DRIVE               = 15;
  ERROR_CURRENT_DIRECTORY           = 16;
  ERROR_NOT_SAME_DEVICE             = 17;
  ERROR_NO_MORE_FILES               = 18;
  ERROR_WRITE_PROTECT               = 19;
  ERROR_BAD_UNIT                    = 20;
  ERROR_NOT_READY                   = 21;
  ERROR_BAD_COMMAND                 = 22;
  ERROR_CRC                         = 23;
  ERROR_BAD_LENGTH                  = 24;
  ERROR_SEEK                        = 25;
  ERROR_NOT_DOS_DISK                = 26;
  ERROR_SECTOR_NOT_FOUND            = 27;
  ERROR_OUT_OF_PAPER                = 28;
  ERROR_WRITE_FAULT                 = 29;
  ERROR_READ_FAULT                  = 30;
  ERROR_GEN_FAILURE                 = 31;
  ERROR_SHARING_VIOLATION           = 32;
  ERROR_LOCK_VIOLATION              = 33;
  ERROR_WRONG_DISK                  = 34;
  ERROR_SHARING_BUFFER_EXCEEDED     = 36;
  ERROR_HANDLE_EOF                  = 37;
  ERROR_HANDLE_DISK_FULL            = 38;
  ERROR_NOT_SUPPORTED               = 50;
  ERROR_REM_NOT_LIST                = 51;
  ERROR_DUP_NAME                    = 52;
  ERROR_BAD_NETPATH                 = 53;
  ERROR_NETWORK_BUSY                = 54;
  ERROR_DEV_NOT_EXIST               = 55;
  ERROR_TOO_MANY_CMDS               = 56;
  ERROR_INVALID_PARAMETER           = 87;

  NERR_Success                      = 0;  
  NERR_BASE                         = $2100;
  NERR_BadPassword                  = NERR_BASE + 103;
  NERR_UserNotFound                 = NERR_BASE + 121;
  NERR_NotPrimary                   = NERR_BASE + 126;
  NERR_SpeGroupOp                   = NERR_BASE + 134;
  NERR_PasswordTooShort             = NERR_BASE + 145;
  NERR_InvalidComputer              = NERR_BASE + 251;
  NERR_LastAdmin                    = NERR_BASE + 352;
  NERR_NetNameNotFound              = NERR_BASE + 210;  

  MAX_PREFERRED_LENGTH              = $FFFFFFFF;  
type
  USER_INFO_1 = record
    usri1_name: LPWSTR;
    usri1_password: LPWSTR;
    usri1_password_age: DWORD;
    usri1_priv: DWORD;
    usri1_home_dir: LPWSTR;
    usri1_comment: LPWSTR;
    usri1_flags: DWORD;
    usri1_script_path: LPWSTR;
  end;
  lpUSER_INFO_1 = ^USER_INFO_1;

  TUser_Info_1008 = record
    usri1008_flags: DWORD;
  end;
  PUser_Info_1008 = ^TUser_Info_1008;

  SHARE_INFO_0 = record
    shi0_netname: LPWSTR;
  end;
  lpSHARE_INFO_0 = ^SHARE_INFO_0;

  SHARE_INFO_1 = record
    shi1_netname: LPWSTR;
    shi1_type: DWORD;
    shi1_remark: LPWSTR;
  end;
  lpSHARE_INFO_1 = ^SHARE_INFO_1;

  _SHARE_INFO_502 = record
    shi502_netname: LPWSTR;
    shi502_type: DWORD;
    shi502_remark: LPWSTR;
    shi502_permissions: DWORD;
    shi502_max_uses: DWORD;
    shi502_current_uses: DWORD;
    shi502_path: LPWSTR;
    shi502_passwd: LPWSTR;
    shi502_reserved: DWORD;
    shi502_security_descriptor:PSecurityDescriptor;
  end;
  lpSHARE_INFO_502 = ^_SHARE_INFO_502;
    
function NetUserEnum(ServerName: PWideChar;Level, Filter: DWORD;
                     var Buffer: Pointer;PrefMaxLen: DWORD;
                     var EntriesRead,TotalEntries,ResumeHandle: DWORD): LongWord;
                     stdcall; external 'netapi32.dll';
function NetApiBufferFree(pBuffer: PByte): LongInt;
                     stdcall;  external 'netapi32.dll';
function NetUserGetInfo(ServerName, username: PWideChar;Level: DWORD;
                     var Buffer: Pointer): LongWord;
                     stdcall;  external 'netapi32.dll';                     
function NetUserSetInfo(ServerName, username: PWideChar;Level: DWORD;
                     var Buffer: Pointer;var parm_err: DWORD): LongWord;
                     stdcall;  external 'netapi32.dll';
function NetUserChangePassword(domainname, username, oldpassword, newpassword: PWideChar): LongWord;
                     stdcall;  external 'netapi32.dll';


function NetShareEnum(ServerName: PWideChar; Level: DWORD;
                     var Buffer: Pointer;PrefMaxLen: DWORD;
                     var EntriesRead,TotalEntries,ResumeHandle: DWORD): LongWord;
                     stdcall; external 'netapi32.dll';
function NetShareDel(ServerName, netname: PWideChar; reserved: DWORD): LongWord;
                     stdcall;  external 'netapi32.dll';                     
implementation

end.
